/*
 * Copyright FUOC.  All rights reserved.

 */
package managedbean;

import java.io.Serializable;
import java.util.Collection;
import java.util.Iterator;
import java.util.Properties;

import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;

import jpa.CustomerJPA;
import jpa.OrderJPA;
import jpa.OrderdetailJPA;
import ejb.CustomerFacadeRemote;
import ejb.OrderFacadeRemote;

/**
 * Managed Bean ShowPetMBean
 */
@ManagedBean(name = "showorder")
@SessionScoped
public class ShowOrderMBean implements Serializable{
	
	private static final long serialVersionUID = 1L;	
	
	@EJB
	private OrderFacadeRemote orderFR;

	private Collection<OrderdetailJPA> orderdetail;
	private int idOrder;
		
	public ShowOrderMBean() throws Exception 
	{
		super();
	}
	
	public ShowOrderMBean(int idOrder) throws Exception 
	{
		setIdOrder(idOrder);
	}
	
	public Collection<OrderdetailJPA> getOrderdetail() {
		return orderdetail;
	}

	public int getIdOrder() {
		return idOrder;
	}
	
	public void setIdOrder(int idOrder) throws Exception {
		this.idOrder = idOrder;
		ShowOrder();
	}

	
	@SuppressWarnings("unchecked")
	public void ShowOrder() throws Exception
	{	
		Properties props = System.getProperties();
		Context ctx = new InitialContext(props);
		orderFR = (OrderFacadeRemote) ctx.lookup("java:app/PracticalCaseStudyJEE.jar/OrderFacadeBean!ejb.OrderFacadeRemote");
		orderdetail = (Collection<OrderdetailJPA>)orderFR.showOrder(idOrder);
	}

	
}

